1 00:00:00,560 --> 00:00:00,770 All right. 2 00:00:00,770 --> 00:00:07,190 So now that we created our landmines using random numbers on a flat terrain, how do we solve that problem 3 00:00:07,190 --> 00:00:11,560 if we have variable terrain like hills and water and things like that? 4 00:00:11,570 --> 00:00:14,690 I'm going to do that today with my health pick ups. 5 00:00:15,680 --> 00:00:22,850 So let's move away from our sign where our flat landmine field is and make some variable terrain. 6 00:00:24,390 --> 00:00:26,370 Let me open my terrain editor here. 7 00:00:26,420 --> 00:00:30,470 We're not going to spend too much time, but let's just put a hill in here and maybe some water. 8 00:00:30,480 --> 00:00:35,490 So with grass selected, I'm going to go ahead and grow that. 9 00:00:35,700 --> 00:00:37,110 Make that a little bit bigger. 10 00:00:37,110 --> 00:00:38,490 Strength is fine. 11 00:00:38,670 --> 00:00:40,970 Let me turn my plane lock off. 12 00:00:40,980 --> 00:00:42,100 I do have it off. 13 00:00:42,120 --> 00:00:42,900 All right. 14 00:00:43,560 --> 00:00:44,190 There we go. 15 00:00:44,290 --> 00:00:44,820 Oh, man. 16 00:00:44,820 --> 00:00:47,370 I went to Stone Grass. 17 00:00:49,010 --> 00:00:49,500 There we go. 18 00:00:49,520 --> 00:00:50,690 We just got right over it. 19 00:00:50,690 --> 00:00:52,550 So we've got this hill going here. 20 00:00:56,410 --> 00:00:57,500 That's your work. 21 00:00:57,980 --> 00:00:59,470 A little bit of rock in there. 22 00:00:59,590 --> 00:01:01,300 Maybe we'll put some rock in there. 23 00:01:01,540 --> 00:01:02,500 Let's get some rock. 24 00:01:02,950 --> 00:01:04,960 Maybe make this thing smaller. 25 00:01:08,450 --> 00:01:11,090 Get a little Machu Picchu thing going. 26 00:01:12,470 --> 00:01:12,920 Cool. 27 00:01:12,950 --> 00:01:14,480 Maybe some water, too. 28 00:01:14,510 --> 00:01:15,770 Let's go to paint. 29 00:01:17,210 --> 00:01:20,570 Go down to water and I'm going to make that a little bigger. 30 00:01:23,050 --> 00:01:24,040 Here we go. 31 00:01:24,200 --> 00:01:25,270 Got a lake. 32 00:01:26,300 --> 00:01:28,070 They make this one a little small here. 33 00:01:30,490 --> 00:01:31,270 Cool. 34 00:01:31,390 --> 00:01:37,570 All right, Now that we got some, we got some unusual terrain, let's go ahead and put a center point 35 00:01:37,570 --> 00:01:43,300 here so we make sure that our health pick ups are over the funny terrain just to make sure it works. 36 00:01:43,300 --> 00:01:46,420 You could you could expand this out to the whole terrain. 37 00:01:46,420 --> 00:01:50,830 But I want to make sure that we have some some good test area. 38 00:01:51,370 --> 00:01:53,620 So I'm going to add a block right here. 39 00:01:54,040 --> 00:01:54,910 There we go. 40 00:01:55,150 --> 00:01:56,050 That's pretty good. 41 00:01:56,050 --> 00:01:56,830 That's centered. 42 00:01:56,830 --> 00:02:00,340 Let's just call this like health center. 43 00:02:01,460 --> 00:02:03,170 Health center. 44 00:02:03,770 --> 00:02:04,140 Nice. 45 00:02:04,160 --> 00:02:05,660 Going to be a little reference point. 46 00:02:05,660 --> 00:02:07,340 I'm going to make it invisible. 47 00:02:08,720 --> 00:02:09,620 Let's see. 48 00:02:09,650 --> 00:02:10,940 Turn can collide off. 49 00:02:10,940 --> 00:02:12,170 So don't trip over it. 50 00:02:12,200 --> 00:02:15,170 Turn anchored on so it doesn't fall down through the ground. 51 00:02:15,170 --> 00:02:19,140 And then let's scroll all the way up to where it says transparency. 52 00:02:19,160 --> 00:02:20,690 Make that one. 53 00:02:21,380 --> 00:02:26,490 Let's go down to server storage and take a quick look at our health pickup. 54 00:02:26,510 --> 00:02:28,140 We have a health pick up here. 55 00:02:28,160 --> 00:02:30,620 I'm going to do a control D to duplicate it. 56 00:02:30,620 --> 00:02:35,270 I'm going to drag it up into our workspace so we can see it. 57 00:02:35,630 --> 00:02:36,020 All right. 58 00:02:36,020 --> 00:02:37,850 So it's really far away. 59 00:02:37,850 --> 00:02:40,880 I can't even see it way over there. 60 00:02:40,880 --> 00:02:49,430 Let's just go ahead and get our health center and then I will do a control C on the position under C 61 00:02:49,460 --> 00:02:51,440 frame for the health center. 62 00:02:51,440 --> 00:02:58,310 And then I want to go to my health pickup and then under C frame position control V boom, there it 63 00:02:58,310 --> 00:02:58,490 is. 64 00:02:58,490 --> 00:02:59,240 It's in the ground. 65 00:02:59,240 --> 00:03:00,710 I'm going to lift that up a little bit. 66 00:03:01,040 --> 00:03:09,800 Now I want this to be floating about three studs above the ground and I want to be able to randomly 67 00:03:09,800 --> 00:03:11,300 select terrain. 68 00:03:11,300 --> 00:03:18,020 But we don't know the height of the terrain and we also want it to be three studs above the water. 69 00:03:18,020 --> 00:03:24,890 If we pick an X and a Z out here, let's go ahead and get started with that using a technique called 70 00:03:24,890 --> 00:03:26,360 ray casting. 71 00:03:27,950 --> 00:03:30,050 Let's go ahead and delete this example. 72 00:03:30,050 --> 00:03:30,980 Health pickup. 73 00:03:31,130 --> 00:03:33,770 Right click, delete. 74 00:03:33,770 --> 00:03:36,620 And we're going to open our session utils. 75 00:03:36,620 --> 00:03:42,710 I have it open right here, but if you don't have it, it's under server or server script service right 76 00:03:42,710 --> 00:03:43,070 there. 77 00:03:43,070 --> 00:03:44,720 You double click and open it up. 78 00:03:44,960 --> 00:03:51,290 All right, now we're going to add a helper function, let's say a local function, and I'm going to 79 00:03:51,290 --> 00:03:57,650 call this cast ray down for height. 80 00:03:57,680 --> 00:04:04,340 I want to determine the height of the terrain, given an X and a Z, Right. 81 00:04:04,340 --> 00:04:10,310 So the X and the Z is the is the flat part of the map and the Y is the height. 82 00:04:10,490 --> 00:04:15,530 So I have my X, I need a Y and I have a Z. 83 00:04:16,130 --> 00:04:20,030 Let's get a variable called origin. 84 00:04:20,030 --> 00:04:24,050 And origin is going to be the origin of the ray. 85 00:04:24,050 --> 00:04:28,820 So I'll say origin equals vector three new. 86 00:04:28,820 --> 00:04:37,430 Well, we have our X and our Z, we need a Y, and I'm going to go with 300 studs above my terrain. 87 00:04:37,430 --> 00:04:40,310 I know my hills aren't going to be higher than 300 studs. 88 00:04:40,310 --> 00:04:43,820 If you have high hills, go ahead and increase that number. 89 00:04:44,330 --> 00:04:44,660 All right. 90 00:04:44,660 --> 00:04:50,930 I'm going to need a stop point on my ray and I want to make sure I go past the terrain. 91 00:04:50,930 --> 00:04:52,760 I'm going to be looking down. 92 00:04:52,760 --> 00:04:55,850 I'm going to say vector three new. 93 00:04:55,850 --> 00:05:00,620 I know my X, I'm going to go -20 on the Y. 94 00:05:00,620 --> 00:05:02,540 You could go past that if you want. 95 00:05:02,540 --> 00:05:08,660 But I know I'm not going more than -20 in any of my terrain areas and I have my same Z. 96 00:05:08,690 --> 00:05:10,730 We're going to look straight down. 97 00:05:11,330 --> 00:05:12,860 I need another variable. 98 00:05:13,400 --> 00:05:16,070 I'm going to call it deer for direction. 99 00:05:16,550 --> 00:05:20,720 I'm going to get the stop minus the origin. 100 00:05:21,210 --> 00:05:21,680 All right. 101 00:05:21,760 --> 00:05:23,270 I know that's a little more than direction. 102 00:05:23,270 --> 00:05:23,480 Right? 103 00:05:23,480 --> 00:05:28,130 Direction would just be a unit vector, but that's fine if you don't know what that is, that's fine, 104 00:05:28,130 --> 00:05:29,750 because we're not going to care. 105 00:05:29,750 --> 00:05:31,910 So I'm going to get this result. 106 00:05:32,540 --> 00:05:39,530 If I do my workspace, Colon ray cast, I'm going to start with the origin. 107 00:05:39,560 --> 00:05:46,520 See, it tells you right here Cas array using the origin direction and optional ray cast parameters. 108 00:05:46,520 --> 00:05:51,770 We're not going to use ray cast parameters, but that gives you cool things like an ignore list. 109 00:05:51,770 --> 00:05:56,450 Like if you want to ignore the water or you want to ignore certain materials, we're going to do that 110 00:05:56,450 --> 00:05:59,000 when we're using our guns, when we're making guns. 111 00:05:59,000 --> 00:06:04,610 So let's say origin, I need my direction, which is a little more than direction. 112 00:06:04,610 --> 00:06:11,930 It's direction and distance and then nil for our parameters, or you can put nothing there to pass it 113 00:06:11,930 --> 00:06:12,230 in. 114 00:06:12,230 --> 00:06:12,650 Right. 115 00:06:12,650 --> 00:06:14,180 So this will work just fine. 116 00:06:14,180 --> 00:06:16,610 That'll pass in a nil for the parameters. 117 00:06:16,610 --> 00:06:20,630 But I'm going to put this here just so that we know that something could go there. 118 00:06:20,780 --> 00:06:21,530 All right? 119 00:06:21,530 --> 00:06:25,430 If we hit something with our array, like the ground. 120 00:06:25,430 --> 00:06:26,810 Right, we're going to get a result. 121 00:06:26,810 --> 00:06:30,560 So we have to check if result then. 122 00:06:30,740 --> 00:06:31,100 All right. 123 00:06:31,100 --> 00:06:39,650 Well, if we hit the ground, luckily we have something in our result called position that gives me 124 00:06:39,650 --> 00:06:45,050 an X, a Y, and Z at the point of impact of the ray. 125 00:06:45,050 --> 00:06:45,410 Right. 126 00:06:45,410 --> 00:06:46,460 The ray is invisible. 127 00:06:46,460 --> 00:06:47,150 You can't see it. 128 00:06:47,150 --> 00:06:51,620 But now we know where our height is because we have our y value. 129 00:06:51,650 --> 00:06:55,070 We already know the X and z, but we did not know the Y. 130 00:06:55,460 --> 00:07:01,070 So I'm going to do my health pick ups very similar to how I did my landmines. 131 00:07:01,070 --> 00:07:06,170 So I'm going to need a folder much like these, like this mine folder and zombie folder. 132 00:07:06,170 --> 00:07:17,930 Let's go to our workspace, hit the plus, add a folder and I'm going to put a call this health, right? 133 00:07:17,930 --> 00:07:18,980 Maybe health pickups. 134 00:07:18,980 --> 00:07:25,010 Now, health is fine health and we'll go and get a variable for that in our session. 135 00:07:25,010 --> 00:07:26,000 Utils. 136 00:07:26,210 --> 00:07:30,140 Local health Folder. 137 00:07:30,140 --> 00:07:32,630 Workspace Health. 138 00:07:33,490 --> 00:07:34,260 All righty. 139 00:07:34,270 --> 00:07:36,940 Let's go down to where our minds are. 140 00:07:36,970 --> 00:07:39,130 This is going to be very, very similar. 141 00:07:40,330 --> 00:07:44,020 We'll get a function and we're going to call this from our wave loop. 142 00:07:44,020 --> 00:07:50,260 So it's not going to be local utils place health. 143 00:07:50,260 --> 00:07:50,690 Right? 144 00:07:50,710 --> 00:07:56,950 I'm going to get the number of health and this is going to be similar to the minds. 145 00:07:56,950 --> 00:08:01,710 We're going to have a certain number of health starting out at the beginning of every round. 146 00:08:01,720 --> 00:08:06,790 I'm going to get my center point because I'm not going to spread them throughout the whole world specifically 147 00:08:06,790 --> 00:08:09,760 because I want to check my terrain stuff right now. 148 00:08:09,850 --> 00:08:13,630 And then I'm going to have a distance from my center point. 149 00:08:14,110 --> 00:08:18,430 Now, what we want to do is make a template object of our health pickup. 150 00:08:18,430 --> 00:08:20,860 Remember, in server storage, we have a health pickup. 151 00:08:20,860 --> 00:08:25,410 Make sure it's there and I'll call this PT Health. 152 00:08:25,420 --> 00:08:26,710 That's my template. 153 00:08:26,710 --> 00:08:27,250 Health. 154 00:08:27,250 --> 00:08:33,610 I'm going to get that from server storage server storage weight from child health pickup. 155 00:08:33,610 --> 00:08:35,980 And then I'm just going to clone from there. 156 00:08:36,730 --> 00:08:41,380 I'm also going to get the count of health that are in my health folder. 157 00:08:41,380 --> 00:08:47,410 So I know if I need to make more or how many I need to make health folder Got children. 158 00:08:47,410 --> 00:08:51,250 So I use this little pound sign in front of the health folder colon. 159 00:08:51,250 --> 00:08:54,340 Get children to get the number of elements in that folder. 160 00:08:54,880 --> 00:08:58,120 Now I'm going to do a while loop before down here I did a for loop. 161 00:08:58,120 --> 00:08:59,860 I thought it'd be kind of cool to change it up. 162 00:08:59,860 --> 00:09:07,870 So you see, there's different ways going to say while count is less than the number of health's do. 163 00:09:07,900 --> 00:09:12,540 Let's get our X and Z random numbers right. 164 00:09:12,550 --> 00:09:19,030 So I have an x rand and we have a random number generator. 165 00:09:19,390 --> 00:09:20,530 Next integer. 166 00:09:20,530 --> 00:09:25,480 We are going to go minus distance to distance. 167 00:09:25,480 --> 00:09:31,510 So if I put 50 in there for distance, we have plus plus 52 -50. 168 00:09:31,780 --> 00:09:42,370 Let's do one for the z and brand next integer and I'll do distance two or negative distance the distance. 169 00:09:43,300 --> 00:09:47,290 Now we need to get a position and we also need to have our y value. 170 00:09:47,290 --> 00:09:53,950 So I'm going to say cast Ray down from height. 171 00:09:54,550 --> 00:10:12,130 I'm going to put in my center point dot x plus my x rand and my center point dot Z plus Z, and that's 172 00:10:12,130 --> 00:10:17,860 going to give me my location on the map centered around my center point, which is going to be, I think 173 00:10:17,860 --> 00:10:22,030 I call that health center, but we didn't pass that in yet. 174 00:10:22,030 --> 00:10:23,800 We're going to pass that in from our wave loop. 175 00:10:24,260 --> 00:10:24,760 All right. 176 00:10:24,790 --> 00:10:27,400 And I'm going to get a Y back with this position. 177 00:10:27,400 --> 00:10:33,340 Remember, I'm going to get a whole X, Y, and Z when I get when when the the array collides with the 178 00:10:33,340 --> 00:10:36,370 earth over the X in the Z location. 179 00:10:36,370 --> 00:10:43,630 So I need to move my health three studs up from the earth or the terrain, whatever you want to call 180 00:10:43,630 --> 00:10:49,510 it, I'm going to get this position and I'm going to add three studs to it. 181 00:10:49,510 --> 00:10:54,970 So I'm going to take the old position and add to a new position plus three studs. 182 00:10:54,970 --> 00:10:59,170 I'll do that plus equals factor three new zero. 183 00:10:59,170 --> 00:11:04,180 We're not going to touch the x three, we're going to increase the Y zero, we're not going to touch 184 00:11:04,180 --> 00:11:04,600 the Z. 185 00:11:04,600 --> 00:11:07,990 So that's going to pick up my position by three studs. 186 00:11:08,470 --> 00:11:19,150 Now let's go ahead and get our health by cloning HT health, and then we'll make the parent let's do 187 00:11:19,150 --> 00:11:28,000 this, like make the parent of the health, the health folder, which is going to put the health object 188 00:11:28,000 --> 00:11:29,170 in the health folder. 189 00:11:30,160 --> 00:11:32,440 We'll get the health position. 190 00:11:32,440 --> 00:11:33,970 So we're just going to use position. 191 00:11:33,970 --> 00:11:36,790 We're not going to use move to because it's a single object. 192 00:11:36,790 --> 00:11:44,680 So we could just change the position to pose, which is three studs above the earth on our random X 193 00:11:44,680 --> 00:11:48,280 and Z plus or minus the center location. 194 00:11:49,030 --> 00:11:55,360 We have a debris service which will give our our health a time to live. 195 00:11:55,540 --> 00:11:56,800 Let's do that. 196 00:11:56,800 --> 00:12:02,860 We'll save 5 minutes just to change things around a little bit in case we get one we can't reach or 197 00:12:02,860 --> 00:12:03,520 something. 198 00:12:03,790 --> 00:12:07,240 And then we're going to get a new value for our count. 199 00:12:07,240 --> 00:12:07,470 Right. 200 00:12:07,480 --> 00:12:09,850 Because the health folder is going to have changed. 201 00:12:09,850 --> 00:12:13,840 So just do pound sign health folder, get children. 202 00:12:13,840 --> 00:12:15,040 We're going to come back up here. 203 00:12:15,040 --> 00:12:16,030 We're going to do our check. 204 00:12:16,030 --> 00:12:21,310 If it's if it's not enough, we're just going to go through and continue until we have enough health. 205 00:12:22,150 --> 00:12:26,690 We still need to call this place health from our wave loop. 206 00:12:26,710 --> 00:12:29,360 Let's go ahead and copy it so we don't forget what it is. 207 00:12:29,380 --> 00:12:30,850 Control C. 208 00:12:30,880 --> 00:12:37,040 Go to wave loop, which is also in server script service right there. 209 00:12:37,060 --> 00:12:37,840 Wave loop. 210 00:12:38,200 --> 00:12:39,000 I'm going to go. 211 00:12:39,010 --> 00:12:40,930 Maybe I'll do it above my place. 212 00:12:40,930 --> 00:12:41,680 Mine's. 213 00:12:42,710 --> 00:12:48,110 Let's go ahead and do a control V and I'll just put a weight in there. 214 00:12:48,290 --> 00:12:58,440 So we need a number of health's let's get variables for these local number of health's. 215 00:12:58,730 --> 00:13:00,850 And how many should we get it? 216 00:13:00,890 --> 00:13:08,650 Give it 2020, and then distance from center right. 217 00:13:08,660 --> 00:13:12,800 So we need to get our center point for the health's. 218 00:13:12,800 --> 00:13:14,510 I think I'm going to call this something different. 219 00:13:14,630 --> 00:13:23,900 I'm going to call this health center POS because I don't want it to be too vague here. 220 00:13:23,900 --> 00:13:25,160 How are we going to do that? 221 00:13:25,160 --> 00:13:28,880 We'll do workspace and then I think I have a health center. 222 00:13:28,880 --> 00:13:29,930 There we go. 223 00:13:29,930 --> 00:13:38,090 And then there's a position associated with that that's good and change this control C, Control V and 224 00:13:38,090 --> 00:13:52,190 then we need a distance from the health center, distance from health center, maybe 100, maybe let's 225 00:13:52,190 --> 00:14:00,590 do 50 for our example though, because we want we want it to get a lot of health around our our strange 226 00:14:00,590 --> 00:14:03,470 terrain to see if our recasting is working. 227 00:14:03,470 --> 00:14:06,740 So let's say distance from health center. 228 00:14:07,010 --> 00:14:07,910 Cool. 229 00:14:07,910 --> 00:14:11,690 Let's go to our world and try it out. 230 00:14:11,690 --> 00:14:13,100 I want to do a play from here, though. 231 00:14:13,100 --> 00:14:17,330 I don't want to have to run around, so I'm going to hit this little arrow play here. 232 00:14:23,570 --> 00:14:27,620 And any second we're going to hear eruption. 233 00:14:28,400 --> 00:14:29,180 Look at that. 234 00:14:30,770 --> 00:14:31,580 Look at that. 235 00:14:31,730 --> 00:14:33,290 Three studs high. 236 00:14:33,320 --> 00:14:36,170 So we have this variable terrain. 237 00:14:36,170 --> 00:14:43,640 We're able to calculate out the height of it and then place our pickups appropriately, even over the 238 00:14:43,640 --> 00:14:44,420 water. 239 00:14:44,840 --> 00:14:48,620 And you put water in the ignore list for the ray casting, but we don't have that. 240 00:14:48,620 --> 00:14:49,730 And I didn't want that. 241 00:14:49,730 --> 00:14:51,790 I'd want I wanted it over the water. 242 00:14:51,800 --> 00:14:53,240 That's pretty cool. 243 00:14:53,240 --> 00:14:55,610 So I will see you in the next video.